# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Yufan You <ouuansteve at gmail>

_name=vue-language-tools
pkgname=vue-language-server
pkgver=1.8.22
pkgrel=1
pkgdesc='Language server for Vue'
arch=('any')
url=https://github.com/vuejs/language-tools/tree/master/packages/vue-language-server
license=('MIT')
depends=('nodejs')
makedepends=('git' 'npm' 'pnpm')
optdepends=('typescript: for use in typescript.tsdk')
source=("$_name::git+https://github.com/vuejs/language-tools.git#tag=v$pkgver")
b2sums=('SKIP')

prepare() {
  cd $_name
  pnpm install --frozen-lockfile
}

build() {
  cd $_name
  pnpm build
}

check() {
  cd $_name
  pnpm test
}

package() {
  local _npmdir=/usr/lib/node_modules/@vue/language-server
  install -d "$pkgdir"/{/usr/bin,$_npmdir}
  ln -s $_npmdir/bin/$pkgname.js "$pkgdir"/usr/bin/$pkgname

  cd $_name/packages/language-server
  # Prune unnecessary packages
  rm -r node_modules
  npm install --production

  cp -r bin node_modules out package.json "$pkgdir"/$_npmdir
  install -Dm644 -t "$pkgdir"/usr/share/licenses/$pkgname LICENSE
}
